
def letter(s):
    return ''.join(c for c in s if c.isalpha())
def reverse(s):
    chars = list(s)
    left, right = 0, len(chars) - 1
    while left < right:
        if chars[left].isalpha() and chars[right].isalpha():
            chars[left], chars[right] = chars[right], chars[left]
            left += 1
            right -= 1
        elif not chars[left].isalpha():
            left += 1
        elif not chars[right].isalpha():
            right -= 1
    return ''.join(chars)
def encode(s, shift):
    result = ''
    for c in s:
        if c.isalpha():
            shifted = (ord(c) - 97 + shift) % 26 + 97
            result += chr(shifted)
        else:
            result += c
    return result

s = input("请输入字符串：")
if len(s) == 0 or len(s) > 255:
    print("输入字符串不合法！")
s = letter(s)
s = reverse(s)
shift = 3
s = encode(s, shift)
print("加密后的字符串为：", s)
